package com.genesis.yunnanji.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.genesis.yunnanji.R;
import com.genesis.yunnanji.bean.DiZhouHotelBean;
import com.genesis.yunnanji.bean.DiZhouTripBean;
import com.genesis.yunnanji.utils.DialogFragmentUtils;

import java.util.List;

/**
 * 创建日期：2018/11/1 0001
 * 作者：Kite
 * 描述：
 */
public class DiZhouHotelAdapter extends BaseQuickAdapter<DiZhouHotelBean.ResultBean.ListBean, BaseViewHolder> {

    private Context context;

    public DiZhouHotelAdapter(Context context, @Nullable List<DiZhouHotelBean.ResultBean.ListBean> data) {
        super(R.layout.item_di_zhou_text, data);
        this.context = context;
    }

    Boolean isClick = true;

    @Override
    protected void convert(final BaseViewHolder helper, final DiZhouHotelBean.ResultBean.ListBean item) {
        helper.setText(R.id.tvTitle, item.getTitle());
        helper.setVisible(R.id.llSupDetailsTime, false);
        helper.setText(R.id.tv_supdetails_phone, item.getPhone());
        helper.setText(R.id.tv_supdetails_address, item.getAddr());
        if (TextUtils.isEmpty(item.getDescription())) {
            helper.setVisible(R.id.tvContent, false);
            helper.setVisible(R.id.tvPullDetails, false);
        } else {
            helper.setVisible(R.id.tvContent, true);
            helper.setVisible(R.id.tvPullDetails, true);
            helper.setText(R.id.tvContent, item.getDescription());
        }
        helper.getView(R.id.tv_supdetails_phone).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogFragmentUtils.initDialog(context,item.getPhone());
            }
        });
        helper.getView(R.id.tvPullDetails).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isClick) {
                    isClick = false;
                    ((TextView) (helper.getView(R.id.tvContent))).setEllipsize(null);
                    ((TextView) (helper.getView(R.id.tvContent))).setSingleLine(isClick);
                    ((TextView) (helper.getView(R.id.tvPullDetails))).setText("点击缩回");
                } else {
                    isClick = true;
                    ((TextView) (helper.getView(R.id.tvContent))).setEllipsize(TextUtils.TruncateAt.END);
                    ((TextView) (helper.getView(R.id.tvContent))).setLines(3);
                    ((TextView) (helper.getView(R.id.tvPullDetails))).setText("展开全部");
                }
            }
        });
    }
}
